package level02.four;

import java.io.*;
/**
 * 在 C 盘下创建一个目录 d1,在目录 d1 下创建若干个 txt 文件，并在每一个 txt 文件中添加若
 * 干内容。将所有 txt 文件的内容复制到 D 盘下的 copy.txt 中。
 * * 要求所有 txt 的文件内容都复制到同一个文件中
 */
public class ZiFu {
    public static void main(String[] args) throws IOException {
        //通过字符流完成four
        //在c盘下创建一个目录d1
        File fileD = new File("d:/d1/d.txt");
        File fileE = new File("d:/d1/e.txt");
        File fileF = new File("d:/d1/f_COPY.txt");
        //创建文件
        fileD.createNewFile();
        fileE.createNewFile();
        fileF.createNewFile();
        //构造读取和写入流
        BufferedWriter fileWriterD = new BufferedWriter(new FileWriter("d:/d1/d.txt"));
        BufferedWriter fileWriterE = new BufferedWriter(new FileWriter("d:/d1/e.txt"));
        BufferedWriter fileWriterF = new BufferedWriter(new FileWriter("d:/d1/f_COPY.txt"));

        BufferedReader fileReaderD = new BufferedReader(new FileReader("d:/d1/d.txt"));
        BufferedReader fileReaderE = new BufferedReader(new FileReader("d:/d1/e.txt"));
        fileWriterD.write("在d中添加一点文件");
        fileWriterD.flush();
        fileWriterE.write("在e中添加一点文件");
        fileWriterE.flush();
        //往f.txt中复制文件内容

        fileWriterF.write(fileReaderD.readLine());
        fileWriterF.write("\r\n");
        fileWriterF.flush();
        fileWriterF.write(fileReaderE.readLine());
        fileWriterF.write("\r\n");
        fileWriterF.flush();
        System.out.println("复制成功");
    }
}
